import Mock from 'mockjs';

// 发送消息
Mock.mock('/api/v1/chat/send', 'post', (options: { body: string }) => {
  const { message } = JSON.parse(options.body);
  return {
    code: 200,
    data: {
      messageId: Mock.Random.guid(),
      content: `这是对"${message}"的模拟回复`,
      timestamp: Mock.Random.datetime(),
      references: [
        {
          title: Mock.Random.title(),
          content: Mock.Random.paragraph(),
          source: Mock.Random.url()
        }
      ]
    },
    message: 'success'
  };
});

// 获取历史消息
Mock.mock(/\/api\/v1\/chat\/history(\?.*)?$/, 'get', () => {
  const messages = Array(5).fill(null).map(() => ({
    messageId: Mock.Random.guid(),
    role: Mock.Random.pick(['user', 'assistant']),
    content: Mock.Random.sentence(),
    timestamp: Mock.Random.datetime(),
    references: Mock.Random.boolean() ? [
      {
        title: Mock.Random.title(),
        content: Mock.Random.paragraph(),
        source: Mock.Random.url()
      }
    ] : undefined
  }));

  return {
    code: 200,
    data: {
      total: 100,
      list: messages
    },
    message: 'success'
  };
});

// 删除聊天记录
Mock.mock('/api/v1/chat/history', 'delete', () => {
  return {
    code: 200,
    message: '删除成功'
  };
});

// 导出聊天记录
Mock.mock('/api/v1/chat/export', 'post', () => {
  return {
    code: 200,
    data: {
      url: Mock.Random.url()
    },
    message: 'success'
  };
});

// 设置响应延迟
Mock.setup({
  timeout: '100-600'
});